<extend name="Public/group"/>

<block name="body">
    <div class="row">

        <div class="col-xs-12">

            <div class="fourm-top common_block_border" style="padding: 15px 20px;margin-top: 0;margin-bottom: 15px">

                <div>
                <h4>
                    群组管理

                </h4>
                  </div>

                <div>
                    <ul class="nav nav-tabs" role="tablist" style="font-size: 12px;">
                        <li role="presentation" class="active"><a href="{:U('Group/Manage/index',array('group_id'=>$_GET['group_id']))}">基本信息</a></li>
                        <li role="presentation" ><a href="{:U('Group/Manage/member',array('group_id'=>$_GET['group_id']))}">成员管理</a></li>
                        <li role="presentation" ><a href="{:U('Group/Manage/notice',array('group_id'=>$_GET['group_id']))}">公告发布</a></li>
                        <li role="presentation" ><a href="{:U('Group/Manage/category',array('group_id'=>$_GET['group_id']))}">帖子分类管理</a></li>

                        <a href="{:U('group/index/group',array('id'=>$_GET['group_id']))}" class="btn btn-primary pull-right" style="margin-left: 10px;">返回群组</a>
                        <button class="btn btn-primary pull-right dismiss">解散群组</button>
                    </ul>


                </div>


                <hr style="border-top:0"/>
                <section id="contents">
                    <form class="form-horizontal ajax-form" role="form" action="{:U('Group/Index/doAddGroup')}" method="post" id="edit-article-form">
                        <input type="hidden" name="group_id" value="{$group.id}"/>

                        <div class="row">
                            <!-- 帖子分类 -->
                            <div class="col-sm-12">
                                <div class="form-group">
                                    <label for="inputTitle" class="col-sm-2 control-label">*群组名称</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="title" class="form-control" id="inputTitle" placeholder="群组名称，最多20个字" value="{$group.title|parseWeiboContent}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputType" class="col-sm-2 control-label">*分类</label>
                                    <div class="col-sm-10">
                                        <select name="group_type" class="form-control" id="inputType">
                                            <option value="-1">请选择</option>
                                            <volist name="groupType" id="groupType">
                                                <option <if condition="$group['type_id'] eq $groupType['id']">selected</if> value="{$groupType['id']}">{$groupType['title']|parseWeiboContent}</option>
                                            </volist>

                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="inputDescription" class="col-sm-2 control-label">群组介绍</label>
                                    <div class="col-sm-10">
                                        <textarea name="detail" class="form-control" id="inputDescription" placeholder="群组的介绍" >{$group.detail|parseWeiboContent}</textarea>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="inputDescription" class="col-sm-2 control-label">群组类型</label>
                                    <div class="col-sm-10">
                                        <label for="id_type_0" style="font-weight: normal">
                                        <input id="id_type_0" name="type" value="0" type="radio" <if condition="$group['type'] eq 0"> checked</if> >
                                        公共群组
                                        </label>
                                        <label for="id_type_1" style="font-weight: normal">
                                        <input id="id_type_1" name="type" value="1" type="radio" <if condition="$group['type'] eq 1"> checked</if>>
                                        私有群组
                                        </label>
                                        <div style="color: #999">
                                            （加入公共群组不需要管理员审核，加入私有群组需管理员审核）
                                        </div>
                                    </div>
                                </div>



                                <div class="form-group">
                                    <label for="upload_picture_cover" class="col-sm-2 control-label">群组形象</label>
                                    <div  class="col-sm-10">
                                        <input type="file" id="upload_picture_cover"  >
                                        <div style="color: #999">
                                            （图片尺寸至少：300像素 * 300像素）
                                        </div>

                                        <input type="hidden" name="logo" id="cover_id_cover" value="{$group.logo}"/>

                                        <div class="col-sm-10 upload-img-box" style="margin-top: 10px;width: 250px;">
                                            <div class="upload-pre-item"><img src="{$group.logo|get_cover='path'}"/></div>
                                        </div>
                                    </div>
                                </div>




                                <div class="form-group">
                                    <label for="upload_picture_cover" class="col-sm-2 control-label">背景图片</label>

                                    <div  class="col-sm-10">
                                        <input type="file" id="upload_picture_background"  >
                                        <div style="color: #999;">
                                            （图片建议尺寸：1050像素 * 200像素）
                                        </div>
                                        <input type="hidden" name="background" id="background" value="{$group.background}"/>

                                        <div class="col-sm-10 upload-background-box" style="margin-top: 10px;width: 350px;">
                                            <div class="upload-pre-item"><img src="{$group.background|get_cover='path'}"/></div>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                        <p class="" style="margin-left: 127px">
                            <button type="submit" class="btn btn-large btn-primary" id="submit-button">
                                <span class="glyphicon glyphicon-edit"></span>
                            <span id="submit-content">
                   保存
                            </span>
                            </button>

                        </p>

                    </form>
                </section>
            </div>
        </div>

    </div>
</block>

<block name="script">
    <script type="text/javascript" src="__PUBLIC__/Core/js/ext/atwho/atwho.js"></script>
    <link type="text/css" rel="stylesheet" href="__PUBLIC__/Core/js/ext/atwho//atwho.css"/>
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>


    <script>
        $("#upload_picture_cover").uploadify({
            "height": 30,
            "swf": "__STATIC__/uploadify/uploadify.swf",
            "fileObjName": "download",
            "buttonText": "上传封面",
            "buttonClass": "uploadcover",
            "uploader": "{:U('Home/File/uploadPicture',array('session_id'=>session_id()))}",
            "width": 100,
            'removeTimeout': 1,
            'fileTypeExts': '*.jpg; *.png; *.gif;',
            "onUploadSuccess": uploadPicturecover,
            'overrideEvents': ['onUploadProgress', 'onUploadComplete', 'onUploadStart', 'onSelect'],
            'onFallback': function () {
                alert('未检测到兼容版本的Flash.');
            }, 'onUploadProgress': function (file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) {
                $("#cover_id_cover").parent().find('.upload-img-box').html(totalBytesUploaded + ' bytes uploaded of ' + totalBytesTotal + ' bytes.');
            }, 'onUploadComplete': function (file) {
                //alert('The file ' + file.name + ' finished processing.');
            }, 'onUploadStart': function (file) {
                $('.upload-img-box').html(
                        '<div class="upload-pre-item">上传中...</div>'
                );
                //alert('Starting to upload ' + file.name);
            }, 'onQueueComplete': function (queueData) {
                // alert(queueData.uploadsSuccessful + ' files were successfully uploaded.');
            }
        });
        function uploadPicturecover(file, data) {
            var data = $.parseJSON(data);
            var src = '';
            if (data.status) {
                $("#cover_id_cover").val(data.id);
                src = data.url ||  data.path
                $('.upload-img-box').html(
                        '<div class="upload-pre-item"><img src="' + src + '"/></div>'
                );
            } else {
                toast.error('封面上传失败。', '温馨提示');
            }
        }



        $("#upload_picture_background").uploadify({
            "height": 30,
            "swf": "__STATIC__/uploadify/uploadify.swf",
            "fileObjName": "download",
            "buttonText": "上传背景",
            "buttonClass": "uploadcover",
            "uploader": "{:U('Home/File/uploadPicture',array('session_id'=>session_id()))}",
            "width": 100,
            'removeTimeout': 1,
            'fileTypeExts': '*.jpg; *.png; *.gif;',
            "onUploadSuccess": uploadbackground,
            'overrideEvents': ['onUploadProgress', 'onUploadComplete', 'onUploadStart', 'onSelect'],
            'onFallback': function () {
                alert('未检测到兼容版本的Flash.');
            }, 'onUploadProgress': function (file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) {
                $("#background").parent().find('.upload-background-box').html(totalBytesUploaded + ' bytes uploaded of ' + totalBytesTotal + ' bytes.');
            }, 'onUploadComplete': function (file) {
                //alert('The file ' + file.name + ' finished processing.');
            }, 'onUploadStart': function (file) {
                $('.upload-background-box').html(
                        '<div class="upload-pre-item">上传中...</div>'
                );
                //alert('Starting to upload ' + file.name);
            }, 'onQueueComplete': function (queueData) {
                // alert(queueData.uploadsSuccessful + ' files were successfully uploaded.');
            }
        });
        function uploadbackground(file, data) {
            var data = $.parseJSON(data);
            var src = '';
            if (data.status) {
                $("#background").val(data.id);
                src = data.url ||  data.path
                $('.upload-background-box').html(
                        '<div class="upload-pre-item"><img src="' + src + '"/></div>'
                );
            } else {
                toast.error('背景上传失败。', '温馨提示');
            }
        }


    </script>

    <script>
        //点击编辑或发表按钮之后
        $(function () {

            var submitCount = 0;


            function showSubmitError(message) {
                $('#submit-button').removeClass('disabled');
                var isEdit = $('#isEdit').val();
                var text = '';
                if (isEdit) {
                    text = '编辑帖子';
                } else {
                    text = '发表帖子';
                }
                $('#submit-content').text(text);
                toast.error(message, '错误');
            }

            function showSubmitSuccess(message, url) {
                toast.success(message, '温馨提示');
                setTimeout(function () {
                    location.href = url;
                }, 1500);
            }

            function showSubmitting() {
                $('#submit-button').attr('class', 'btn btn-primary disabled');
                $('#submit-content').text('正在提交');
            }

            $('.dismiss').click(function(){
                if(confirm('确定要解散该群组么？')){
                    var obj = $(this)
                    var group_id = '{$group_id}';
                    $.post("{:U('group/manage/dismiss')}",{group_id:group_id},function(res){
                        handleAjax(res);

                    })
                }

            })

        })
    </script>
</block>
